package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 质量检查类型枚举
 *
 * <p>管理质量检查的类型分类，包括自动检查、人工检查、同行评审、主管评审、抽样检查。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-14
 */
public enum QualityCheckType implements BaseEnum {

    /** 自动检查 */
    AUTOMATIC("AUTOMATIC", "自动检查"),

    /** 人工检查 */
    MANUAL("MANUAL", "人工检查"),

    /** 同行评审 */
    PEER_REVIEW("PEER_REVIEW", "同行评审"),

    /** 主管评审 */
    SUPERVISOR_REVIEW("SUPERVISOR_REVIEW", "主管评审"),

    /** 抽样检查 */
    SAMPLE_CHECK("SAMPLE_CHECK", "抽样检查");

    private final String code;
    private final String description;

    QualityCheckType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static QualityCheckType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Quality check type code cannot be null or empty");
        }

        for (QualityCheckType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown quality check type code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static QualityCheckType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Quality check type description cannot be null or empty");
        }

        for (QualityCheckType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown quality check type description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}